import type { App } from "vue";
function useResize(el: HTMLElement, callback: Function) {
  let resize = new ResizeObserver((entries) => {
    callback(entries[0].contentRect);
  });
  resize.observe(el);
}

const install = (app: App) => {
  app.directive("resize", {
    mounted(el, binding) {
      useResize(el, binding.value);
    },
  });
};
useResize.install = install;

export default useResize;
